<template>
  <div class="container">
    <!-- <div class="container-1200"> -->
    <div class="admin-container">
      <div class="flexWithJusBetween mg-B20">
        <div class="title">项目资料列表</div>
        <ExportList2Excel
          ref="exportList2Excel"
          @handleExport="handleExport"
          name="导出项目资料"
        />
      </div>
      <div v-show="queryType == false">
        <el-form ref="warehouseForm" label-width="80px" :inline="true">
          <el-form-item label="关键词">
            <el-input
              prefix-icon="el-icon-search"
              v-model="query.keyword"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="企业名称">
            <el-select
              v-model="query.companyId"
              placeholder="请选择企业"
              clearable
            >
              <el-option
                :label="item.name"
                :value="item.id"
                v-for="item in companyList"
                :key="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="填报时间">
            <el-date-picker
              v-model="query.date"
              value-format="yyyy-MM-dd"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-button
            style="margin-left: 10px"
            icon="el-icon-search"
            type="primary"
            @click="submitQuery"
            >查询
          </el-button>
          <el-button
            style="margin-left: 10px"
            icon="el-icon-refresh-right"
            type="info"
            @click="resetQuery"
            >重置
          </el-button>
        </el-form>
      </div>
      <el-table :data="tableData" style="width: 100%" border align="center">
        <el-table-column prop="projectName" label="项目名称" align="center">
        </el-table-column>
        <el-table-column prop="compnayName" label="企业名称" align="center">
        </el-table-column>
        <el-table-column prop="linkman" label="负责人" align="center">
        </el-table-column>
        <el-table-column prop="phone" label="负责人联系方式" align="center">
        </el-table-column>
        <el-table-column prop="createDate" label="填报时间" align="center">
        </el-table-column>
        <el-table-column label="项目状态" align="center">
          <template slot-scope="scope">
            <div>
              {{ projectStatusFormate("project_status-" + scope.row.status) }}
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button @click="viewProject(scope.row)" type="text" size="small"
              >查询</el-button
            >
            <!-- <el-button type="text" size="small" @click="viewProjectActivity(scope.row)"
              >查询项目活动列表</el-button
            >
            <el-button type="text" size="small" @click="viewProjectExecute(scope.row)"
              >查询项目运营列表</el-button
            > -->
            <!-- <el-button
              type="text"
              size="small"
              @click="projectExecute(scope.row)"
              >运营月报</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="projectActivity(scope.row)"
              >查看活动</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
      <el-footer class="el-footerBox">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="pageSize"
          :current-page.sync="pageNum"
          @current-change="getProjectList"
        >
        </el-pagination>
      </el-footer>
    </div>
  </div>
</template>

<script>
import { validUsername } from "@/utils/validate";
import ExportList2Excel from "@/components/ExportList2Excel";
import utils from "@/utils/utils.js";
import { find as companyFind,list as companyList  } from "@/api/adminCompany";
import { list as projectList } from "@/api/adminProject";

export default {
  components: {ExportList2Excel},
  name: "project",
  data() {
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("密码不能少于6位"));
      } else {
        callback();
      }
    };
    return {
      queryType: false,
      query: {
        keyword: "",
        date:"",
        startDate:"",
        endDate:"",
        companyId: "",
      },
      companyId: "",
      total:0,
      pageNum:1,
      pageSize:20,
      tableData: [],
      companyInfo: "",
      companyList:[],

      //字典信息
      projectStatusDict:[],
      taxTypeDict:[],
      registrationDict:[],
      lzjdDict:[],
      projectCategoryDict:[],
      industryDict:[],
      projectCategoryDictPromise:"",

      projectStatusDictPromise:"",
      //获取字典的promise
      taxTypeDictPromise: "",
      registrationDictPromise: "",
      lzjdDictPromise: "",
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    this.taxTypeDictPromise = utils.getDictList("tax_type", (res) => {
      this.taxTypeDict = res.data;
    });
    this.registrationDictPromise = utils.getDictList("registration", (res) => {
      this.registrationDict = res.data;
    });
    this.lzjdDictPromise = utils.getDictList("lzjd", (res) => {
      this.lzjdDict = res.data;
    });
    this.projectCategoryDictPromise = utils.getDictList("projectCategory", (res) => {
      this.projectCategoryDict = res.data;
    });
    this.projectStatusDictPromise = utils.getDictList("project_status", (res) => {
      this.projectStatusDict = res.data;
    });
    this.industryDictPromise = utils.getDictList("industry", (res) => {
      this.industryDict = res.data;
    });
  },

  mounted() {
    // if (this.$route.query) {
    //   this.companyId = this.$route.query.companyId;
    //   this.companyFind(this.companyId);
    // }
    let _this = this
    _this.getCmpanyList()
    Promise.all([this.projectStatusDictPromise]).then(
      (res) => {
        //console.log("字典已经全部加载完成--");
        this.getProjectList(this.companyId);
      }
    );
    
  },

  destroyed() {},

  methods: {
    //调用数据导出的函数
    handleExport(PageParam) {
      var _this = this;
      this.keyword = this.query;
      //要导出函数携带的参数
      let data = {};
      data.tHeader = [
        "项目名称",
        "项目类别",
        "启动时间",
        "建设内容及目标",
        "三年计划(投资，收益，岗位)",

        '企业名称',
        '负责人',
        '负责人联系方式',

        '行业类别',
        '行业类别',
        '纳税类型',

        '是否有IP、新三板、并购退出',
        '是否高薪技术企业',
        '是否科技型中小企业',
        '融资进度',
        '企业资产估计(万元)',

        '企业成立时注册资本(千元)',
        '获取天使或风险投资额(千元)',

         '企业本年度投资额(千元)',
        '企业上半总收入(千元)',
        '当年获取政府资金(千元)',
        '企业净利润(千元)',
        '企业总出口额(千元)',
        '企业研究与试验发展（R&D）经费支出',
        '企业实际上缴税费',

        '企业从业人员',
        '企业从业人员(博士)',
        '企业从业人员(硕士)',
        '企业从业人员(本科)',
         '企业从业人员(大专)',
 '留学人员',
     '千人计划人数',
     '双百人才人数',
   '吸纳应届毕业生',

     '知识产权申请数',
       '知识产权授权数',
         '知识产权发明专利',

       '拥有有效知识产权',
       '有效知识产权发明专利',
   '软件著作权',
   '植物新品种',
     '集成电路布图', 'PCT专利',
     '购买国外专利',
       '技术合同交易数量',
       '技术合同交易金额',
       '当年承担国家级科技计划项目数',
     '当年获取市级以上奖励',
       '产学研合作项目数',
       '产学研合作项目总金额',

       '建设双创载体数量', 
       '孵化器',
 '众创空间',
 '台青创基地',
     '技术创新中心',
     '工程研究中心',
     '产业创新中心',
     '新型研发机构',
      ];
    data.multiHeader = ["data.tHeader"]
    data.mergesRule = [
    // 设置A3-A9的单元格合并
    {s: {r: 0, c: 0}, e: {r: 0, c: 18}}
  ]
      data.filterVal = [
        'projectName',
        'projectCategoryId',
        'startDate',
        'jsmb',
        'syjh',

        'compnayName', 
        'linkman', 
        'phone', 

        'industry', 
        'registration', 
        'taxType', 

        'isIpo', 
        'isHighSalary', 
        'isKjxzxqy',
        'lzjd',
        'zcgz', 

        'zczb', 
        'lzjr', 

        'bytz', 
        'sbysl', 
        'dyzfzj', 
        'qyjll', 
        'qyzck', 
        'rdjfzc',
        'qysjsjsf',

        'employeeNum',
        'bsyg', 
        'ssyg', 
        'bkyg', 
        'dzyg', 

        'lxry', 
        'zrjlrs', 
        'sbrcrs', 
        'yjbys', 

        'zscqsq', 
        'zscqsqs', 
        'zscqfmzl', 

        'yyzscqs', 
        'yxzscqs', 
        'rjzzq', 
        'zwxpz', 
        'jcdlbt', 
        'pct', 
        'gmgwzl', 
        'jshtjys', 
        'jshtjyr', 
      'gjkjxms', 
       'cjysjl', 
        'cxyhzxm', 
        'cxyhzjr', 

        'jssczts', 
        'fhq', 
        'zckj', 
        'dqjd', 
        'jscxzx', 
        'gcyjzx', 
        'cycxzx', 
        'xxyfjg', 
      ];
      data.filename = "项目资料表";

      let params = new URLSearchParams();
      params.append("status", 2);
      params.append("companyId", _this.query.companyId);
      params.append("startDate", _this.query.startDate);
      params.append("endDate", _this.query.endDate);
      params.append("keyword", _this.query.keyword);
      params.append('pageNum', 1);
      params.append('pageSize', 10000);
      projectList(params)
        .then((res) => {
          console.log("ProjectList成功获取数据--", res);
          if (res.type == "success") {
            if (res.data.data.length > 0) {
              res.data.data.map((item) => {
                item.startDate = utils.dateFormatter(item.startDate);
                item.taxType = this.taxTypeFormate(item.taxType);
                item.projectCategoryId = this.projectCategoryFormate(item.projectCategoryId);
                item.lzjd = this.lzjdFormate(item.lzjd);
                item.industry = this.industryFormate(item.industry);
                item.registration = this.registrationFormate(item.registration);
                item.isHighSalary = item.isHighSalary == true ? "是" : "不是";
                item.isKjxzxqy = item.isKjxzxqy == true ? "是" : "不是";
                item.isIpo = item.isIpo == true ? "是" : "不是";
              });
            }
            data.list = res.data.data;
            _this.$refs.exportList2Excel.handleDownload(data);
          }
        })
        .catch((err) => {
          console.log('err--',err);
          _this.$refs.exportList2Excel.unlockLoading();
          this.$message.error(err.msg);
        });
    },

    //获取项目列表
    getProjectList(companyId) {
      let _this = this
      let params = new URLSearchParams();
      params.append("status", 2);
      params.append("companyId", _this.query.companyId);
      params.append("startDate", _this.query.startDate);
      params.append("endDate", _this.query.endDate);
      params.append("keyword", _this.query.keyword);
      params.append('pageNum', _this.pageNum);
      params.append('pageSize', _this.pageSize);
      projectList(params)
        .then((res) => {
          console.log("ProjectList成功获取数据--", res);
          if (res.type == "success") {
            this.tableData = res.data.data;
            this.total = res.data.total
            if (this.tableData.length > 0) {
              this.tableData.map((item) => {
                item.startDate = utils.dateFormatter(item.startDate);
                item.createDate = utils.dateFormatter(item.createDate);
              });
            }
          }
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    },

    //条件查询
    submitQuery() {
      console.log('this.query.date--',this.query);
      if(!utils.isNull(this.query.date)){
        this.query.startDate = this.query.date[0]
        this.query.endDate = this.query.date[1]
      }
      this.getProjectList();
    },

    //条件查询
    resetQuery() {
      this.query = {
        keyword: "",
        date:"",
        startDate:"",
        endDate:"",
        companyId:""
      },
        this.getProjectList();
    },

    //新增项目
    addProject() {
      this.$router.push({
        path: "/project/add",
        query: { companyId: this.companyId },
      });
    },

    //查看项目
    viewProject(data) {
      this.$store.dispatch("user/setCloseAliveName", 'projectQueryView')
      this.$router.push({
        path: "/project/queryView",
        query: { projectId: data.id },
      });
    },

    viewProjectActivity(data) {
      this.$router.push({
        path: "/projectActivity/queryList",
        query: { projectId: data.id },
      });
    },

    viewProjectExecute(data) {
      this.$router.push({
        path: "/projectExecute/queryList",
        query: { projectId: data.id },
      });
    },

    //获取公司列表
    getCmpanyList() {
      companyList().then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyList = res.data.data;
        }
      });
    },

    //编辑项目
    editProject(data) {
      this.$router.push({
        path: "/project/edit",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //项目月报表
    projectExecute(data) {
      this.$router.push({
        path: "/projectExecute/list",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //项目活动表
    projectActivity(data) {
      this.$router.push({
        path: "/projectActivity/list",
        query: { projectId: data.id, companyId: this.companyId },
      });
    },

    //获取公司信息
    companyFind(id) {
      companyFind(id).then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyInfo = res.data.company;
        }
      });
    },

    projectStatusFormate(data) {
      return utils.selectDictLabel(this.projectStatusDict, data);
    },

    taxTypeFormate(data) {
      return utils.selectDictLabel(this.taxTypeDict, data);
    },

    registrationFormate(data) {
      return utils.selectDictLabel(this.registrationDict, data);
    },

    lzjdFormate(data) {
      return utils.selectDictLabel(this.lzjdDict, data);
    },

    industryFormate(data) {
      return utils.selectDictLabel(this.industryDict, data);
    },

    dateFormatter(data){
      return utils.dateFormatter(data);
    },

    projectCategoryFormate(data) {
      return utils.selectDictLabel(this.projectCategoryDict, data);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-pagination {
  display: block;
}
</style>
